package com.tyl.controller;
import com.tyl.entity.Account;
import com.tyl.mapper.AccountMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/get")
public class AccountController {
    @Autowired
    private AccountMapper accountMapper;

    Logger log=LoggerFactory.getLogger(AccountController.class);
    @GetMapping("/getAccount")
    @Cacheable(cacheNames = {"temp"})//第一次查询会从数据库中查询，第二次通过缓存查询，可通过日志来检查缓存是否生效
    public List<Account> getAccount(){
        Long start=System.currentTimeMillis();
        List<Account> accounts = accountMapper.selectList(null);
        Long end=System.currentTimeMillis();
        log.info("耗时："+(end-start)+"ms");
        return accounts;
    }
}
